<template>
  <div class="navbar">
    <div class="navbar-logo">
      <img src="https://img.icons8.com/color/48/000000/heart-health.png" alt="康养中心" />
      <span class="logo-text">康养中心患者监护系统</span>
    </div>
    <el-menu
      :default-active="activeIndex"
      mode="horizontal"
      router
      class="navbar-menu"
      background-color="#409EFF"
      text-color="#fff"
      active-text-color="#ffd04b"
    >
      <el-menu-item index="/dashboard">
        <el-icon><Histogram /></el-icon>患者概述
      </el-menu-item>
      <el-menu-item index="/diagnosis">
        <el-icon><FirstAidKit /></el-icon>诊断与治疗计划
      </el-menu-item>
      <el-menu-item index="/living-will">
        <el-icon><Document /></el-icon>医嘱管理
      </el-menu-item>
      <el-menu-item index="/medical-records">
        <el-icon><DocumentCopy /></el-icon>病情记录
      </el-menu-item>
    </el-menu>
    <div class="navbar-user">
      <el-dropdown trigger="click" @command="handleCommand">
        <span class="user-profile">
          <el-avatar :size="32" :icon="User" />
          <span>医生</span>
          <el-icon><ArrowDown /></el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item command="profile">
              <el-icon><User /></el-icon>个人中心
            </el-dropdown-item>
            <el-dropdown-item command="settings">
              <el-icon><Setting /></el-icon>设置
            </el-dropdown-item>
            <el-dropdown-item divided command="logout">
              <el-icon><SwitchButton /></el-icon>退出登录
            </el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { 
  Histogram, 
  FirstAidKit, 
  Document, 
  DocumentCopy, 
  ArrowDown, 
  User, 
  Setting, 
  SwitchButton 
} from '@element-plus/icons-vue'

const router = useRouter()
const userStore = useUserStore()
const activeIndex = ref(router.currentRoute.value.path)

// 处理用户下拉菜单选择
const handleCommand = (command) => {
  if (command === 'profile') {
    router.push('/profile')
  } else if (command === 'logout') {
    // 处理登出逻辑
    userStore.clearUserInfo()
    router.push('/login')
  } else if (command === 'settings') {
    router.push('/settings')
  }
}
</script>

<style scoped>
.navbar {
  display: flex;
  align-items: center;
  background-color: #6fda9b;
  color: white;
  height: 60px;
  padding: 0 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.navbar-logo {
  display: flex;
  align-items: center;
  margin-right: 40px;
}

.logo-text {
  font-size: 18px;
  font-weight: bold;
  margin-left: 10px;
}

.navbar-menu {
  flex-grow: 1;
  border: none;
}

.navbar-user {
  margin-left: 20px;
}

.user-profile {
  display: flex;
  align-items: center;
  cursor: pointer;
  color: white;
}

.user-profile span {
  margin: 0 8px;
}
</style> 
